package org.langqiao.http;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Http499 {
	public static void main(String[] args) {
		//for(int i=0;i<5;i++){
			System.out.println(callPhpSyncData());
		//}
	}
	
	public static String callPhpSyncData() {
    	//校验，从队列中取出来的数据是否正确
		StringBuilder sb = new StringBuilder();
		HttpURLConnection connection = null;
		try {
			URL url = new URL("http://tv.api.cp61.ott.cibntv.net//carousel/tvprogram?version=1&token=VoIhHSkPxY89EkWCthChfQ==&vid=44&start=-36&end=20");   
			connection = (HttpURLConnection) url.openConnection();// 打开连接 
	        //connection.setConnectTimeout(10);
	        connection.setReadTimeout(200);
	        connection.connect();// 连接会话
	        // 获取输入流
	        BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));
	        String line;
	        while ((line = br.readLine()) != null) {// 循环读取流
	            sb.append(line);
	        }
	        br.close();// 关闭流
	        connection.disconnect();
		} catch (Exception e) {
			if(connection != null){
				System.out.println("关闭connection对象");
				connection.disconnect();
			}
		}
		return sb.toString();
        
    }
}
